// JavaScript Document

function zuobiao(n,a,b,c){
	p=(c/2)*Math.cos(0.25*Math.PI) 
	nodetop=[]
	nodeleft=[]
	noderight=[]
	nodetop[0]=''
	nodeleft[0]=''
	noderight[0]=''
	for(var i=1;i<=n;i++){
		nodetop[i]=[]
		nodeleft[i]=[]
		noderight[i]=[]
		nodetop[i][0]=''
		nodeleft[i][0]=''
		noderight[i][0]=''
		for(var j=1;j<=n;j++){
			
			nodetop[i][j]={}
			nodeleft[i][j]={}
			noderight[i][j]={}
			if(i==1&&j==1){
				nodetop[i][j].x=a;
				nodetop[i][j].y=b;
				
				nodeleft[i][j].x=a
				nodeleft[i][j].y=b
				
				noderight[i][j].x=a+(n-1)*c
				noderight[i][j].y=b
				}
			else{
				nodetop[i][j].x=nodetop[i][j-1].x+p||nodetop[i-1][j].x+c;//根据与设定好的节点对象的坐标关系，分别求出此节点的x和y坐标；
				nodetop[i][j].y=nodetop[i][j-1].y-p||nodetop[i-1][j].y;
				
				nodeleft[i][j].x=(nodeleft[i][j-1].x)||(nodeleft[i-1][j].x+c);//根据与设定好的节点对象的坐标关系，分别求出此节点的x和y坐标；
				nodeleft[i][j].y=(nodeleft[i][j-1].y+c)||(nodeleft[i-1][j].y);
				
				noderight[i][j].x=noderight[i][j-1].x||noderight[i-1][j].x+p;//根据与设定好的节点对象的坐标关系，分别求出此节点的x和y坐标；
				noderight[i][j].y=noderight[i][j-1].y+c||noderight[i-1][j].y-p;
	
				}
			}
		}	
		return nodetop,nodeleft,noderight;
	}
	
	function draw(n,a,b,c){
		var canvas=document.getElementById('canvas');
		var hua=canvas.getContext('2d');
		zuobiao(n+1,a,b,c)
		for(var i=1;i<=n;i++){
			for(var j=1;j<=n;j++){
				hua.beginPath();
				hua.moveTo(nodetop[i][j].x,nodetop[i][j].y)
				hua.lineTo(nodetop[i][j+1].x,nodetop[i][j+1].y)
				hua.lineTo(nodetop[i+1][j+1].x,nodetop[i+1][j+1].y)
				hua.lineTo(nodetop[i+1][j].x,nodetop[i+1][j].y)
				hua.lineTo(nodetop[i][j].x,nodetop[i][j].y)
				hua.stroke();
				hua.closePath();
				
				hua.beginPath();
				hua.moveTo(nodeleft[i][j].x,nodeleft[i][j].y)
				hua.lineTo(nodeleft[i][j+1].x,nodeleft[i][j+1].y)
				hua.lineTo(nodeleft[i+1][j+1].x,nodeleft[i+1][j+1].y)
				hua.lineTo(nodeleft[i+1][j].x,nodeleft[i+1][j].y)
				hua.lineTo(nodeleft[i][j].x,nodeleft[i][j].y)
				hua.stroke();
				hua.closePath();
				
				hua.beginPath();
				hua.moveTo(noderight[i][j].x,noderight[i][j].y)
				hua.lineTo(noderight[i][j+1].x,noderight[i][j+1].y)
				hua.lineTo(noderight[i+1][j+1].x,noderight[i+1][j+1].y)
				hua.lineTo(noderight[i+1][j].x,noderight[i+1][j].y)
				hua.lineTo(noderight[i][j].x,noderight[i][j].y)
				hua.stroke();
				hua.closePath();
				
				}
			}
		
		}